package com.yyx.app1.My_function.UI;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.android.volley.toolbox.ImageLoader;
import com.yyx.app1.Data.BaseDataManager;
import com.yyx.app1.Data.testDate;
import com.yyx.app1.MyApp;
import com.yyx.app1.R;
import com.yyx.app1.tool.ImageTool;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by Administrator on 2015/10/25.
 */
@EActivity(R.layout.activity_perfectusernameinfo)
public class PerfectUserNameInfo_Activity extends Activity {
    private BaseDataManager baseDataManager ;
    @ViewById
    EditText sec;

    @ViewById
    ImageView itemview_portrait;

    @AfterViews
    public void init()
    {
        baseDataManager = ((MyApp) getApplication()).getBaseDataManager();
        Bitmap bitmap = baseDataManager.getResDrawable(testDate.defaultPortrait, ImageTool.dip2px(this, 100), ImageTool.dip2px(this, 100));
        itemview_portrait.setImageBitmap(ImageTool.toRoundCorner(bitmap,ImageTool.dip2px(this, 50)));
    }

    @Click
    public void home()
    {
        finish();
    }

    @Click
    public void button()
    {
        finish();
    }

    @Click
    public void sec()
    {
        new AlertDialog.Builder(this).setTitle("性别").setPositiveButton("男", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                getSec("男");
            }
        }).setNegativeButton("女", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                getSec("女");
            }
        }).show();
    }

    public void getSec(String str)
    {
        sec.setText(str);
    }

    @Click
    public void addimage()
    {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try
        {//系统应用获取图片
            Uri uri = data.getData();
            Bitmap bitmap = baseDataManager.getUri(uri, ImageTool.dip2px(this, 100), ImageTool.dip2px(this, 100), false);
            itemview_portrait.setImageBitmap(ImageTool.toRoundCorner(bitmap,ImageTool.dip2px(this, 50)));
            super.onActivityResult(requestCode, resultCode, data);
        }
        catch (Exception e)
        {
            Log.e("异常1510251644", "获取图片取消跳异常空指针,可忽略");
            Log.e("异常1510251644", e.toString());
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            home();
        }
        return true;
    }
}
